package com.edt.ichannel.utils;

import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadUtil {

    public static String readRequestBody(HttpServletRequest request) {
        BufferedReader br = null;
        StringBuilder sb = new StringBuilder();
        try {
            request.setCharacterEncoding("UTF-8");
            br = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
            String line ;
            while (null != (line = br.readLine())) {
                sb.append(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return sb.toString();
    }
}
